package com.cdream.basic.algorithm.leetcode.twoPointer;

/**
 * @author cdream
 * @date 5/15/21
 */
public class Question167 {
    public int[] twoSum(int[] numbers, int target) {
        for (int i = 0; i < numbers.length; i++) {
            int k = target - numbers[i];
            int start = i + 1;
            int end = numbers.length - 1;

            while (start < end) {
                int middle = start + (end - start) / 2;
                if (numbers[middle] == k) {
                    return new int[]{i+1, middle+1};
                } else if (numbers[start] < k) {
                    start = middle+1;
                } else {
                    end = middle-1;
                }
            }
        }
        return new int[]{};
    }


}
